#coding:utf-8
'''
create on 2017-04-20
@author:sandy
'''
import logging
from pycommon import Const
from pycommon import Pack as packet
import GateInfo

def cmdKeepAlive(center,pkt):
    logging.debug(u"center--->login keepAlive")
    pass

def cmdLoginCenterSuc(center,pkt):
    logging.debug(u"center->login loginCenterSuc")
    gateInfo = packet.unpack("S",pkt)
    logging.debug(u"gateInfo1 = %s",gateInfo)
    GateInfo.instance.parse(gateInfo)

def cmdGateUpdate(center,pkt):
    gateInfo = packet.unpack("S",pkt)
    # logging.debug(u"center->login gateInfo2 = %s",gateInfo)
    GateInfo.instance.parse(gateInfo)
    

__cmdTable = {
        Const.CMD_KEEP_ALIVE    : cmdKeepAlive,
        Const.CMD_CT2LG_LOGINSUC : cmdLoginCenterSuc,
        Const.CMD_CT2LG_GATE_UPDATE : cmdGateUpdate
    
    }

def parse(center,cmd,pkt):
    if cmd == Const.CMD_KEEP_ALIVE:
        return
    if cmd == Const.CMD_CT2LG_GATE_UPDATE:
        pass
    else:
        logging.debug("center->login cmd=%d",cmd)
    func = __cmdTable.get(cmd)
    if not func:
        logging.error(u"cmd = %d not found",cmd);
    func(center,pkt)

if __name__ == "__main__":
    pass